package com.aier.admin_new.entity.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import net.eicp.ghostboy.futil.StringUtil;

import org.springframework.jdbc.core.RowMapper;

import com.aier.admin_new.entity.DynamicMessage;


public class DynamicMessageRowMapper implements RowMapper<DynamicMessage> {

    @SuppressWarnings("unused")
    private int type;

    public DynamicMessageRowMapper() {
    }

    public DynamicMessageRowMapper(int type) {
        this.type = type;
    }

    @Override
    public DynamicMessage mapRow(ResultSet rs, int rowNum) throws SQLException {
        return parseHome(new DynamicMessage(), rs);
    }

    public static DynamicMessage parseHome(DynamicMessage h, ResultSet rs) throws SQLException {
        return parseHome(h, rs, null);
    }

    public static DynamicMessage parseHome(DynamicMessage h, ResultSet rs, String su)
        throws SQLException {

        if (StringUtil.isStringNull(su)) {
            su = "";
        } else {
            su += ".";
        }
        try {
            h.setDid(rs.getLong(su+"did"));
        } catch (SQLException e) {
            h.setDid(null);
        }
        try {
            h.setUid(rs.getLong(su+"uid"));
        } catch (SQLException e) {
            h.setUid(null);
        }

        try {
            String str = rs.getString(su+"content");
            if (str != null) {
                str = str.replaceAll("<", "&lt;");
                str = str.replaceAll(">", "&gt;");
            }
           
            h.setContent(str);
        } catch (SQLException e) {
            h.setContent(null);
        }
        try {
            h.setType(rs.getShort(su+"type"));
        } catch (SQLException e) {
            h.setType(null);
        }
        try {
            h.setCdate(rs.getTimestamp(su+"cdate"));
        } catch (SQLException e) {
            h.setCdate(null);
        }
        try {
            h.setNickname(rs.getString(su+"nickname"));
        } catch (SQLException e) {
            h.setNickname(null);
        }
        try {
            h.setHeadimg(rs.getString(su+"headimg"));
        } catch (SQLException e) {
            h.setHeadimg(null);
        }
        return h;
    }


}
